package com;

import java.util.ArrayList;
import java.util.List;

// Building 类表示学院中的建筑
class Building {
    private String name;

    public Building(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

// Course 类表示学院中的课程，课程必须在某个建筑中进行
class Course {
    private String name;
    private Building building;

    public Course(String name, Building building) {
        this.name = name;
        this.building = building;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Building getBuilding() {
        return building;
    }

    public void setBuilding(Building building) {
        this.building = building;
    }
}

// College 类表示学院，包含多个建筑和课程
class College {
    private String name;
    private List<Building> buildings;
    private List<Course> courses;

    public College(String name) {
        this.name = name;
        this.buildings = new ArrayList<>();
        this.courses = new ArrayList<>();
    }

    public void addBuilding(Building building) {
        buildings.add(building);
    }

    public void addCourse(Course course) {
        courses.add(course);
    }

    public List<Building> getBuildings() {
        return buildings;
    }

    public List<Course> getCourses() {
        return courses;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

public class A1_2 {
    public static void main(String[] args) {
        // 创建学院实例
        College college = new College("Moonshot College");

        // 创建建筑实例
        Building building1 = new Building("Building A");
        Building building2 = new Building("Building B");

        // 将建筑添加到学院
        college.addBuilding(building1);
        college.addBuilding(building2);

        // 创建课程实例
        Course course1 = new Course("Introduction to Java", building1);
        Course course2 = new Course("Advanced Java", building2);

        // 将课程添加到学院
        college.addCourse(course1);
        college.addCourse(course2);

        // 打印学院信息
        System.out.println("College Name: " + college.getName());
        for (Building building : college.getBuildings()) {
            System.out.println("Building: " + building.getName());
            for (Course course : college.getCourses()) {
                if (course.getBuilding() == building) {
                    System.out.println("\tCourse: " + course.getName());
                }
            }
        }
    }
}